package cn.easybuy.servlet.order;

import cn.easybuy.entity.Order;
import cn.easybuy.entity.OrderShow;
import cn.easybuy.service.OrderService;
import cn.easybuy.service.impl.OrderServiceImpl;

import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/selMyOrderServlet")
public class SelMyOrderServlet extends HttpServlet {
    private OrderService orderService = new OrderServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        System.out.println(id);
        try {
            List<Order> orders = orderService.SelOrder(id);
            for (int i = 0; i < orders.size(); i++) {
                Order order = orders.get(i);
                String serialNumber = order.getSerialNumber();
                List<OrderShow> orderShows = orderService.SelOrderPar(serialNumber);
                order.setProductList(orderShows);
            }
            req.setAttribute("orders",orders);
            req.getRequestDispatcher("backend/order/orderList.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
